package com.jz.yanshe.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.request.target.BitmapImageViewTarget;

/**
 * Created by Administrator on 2018/1/2.
 */

public class ImageLoaderHelper {
    private static class Instance {
        static ImageLoaderHelper instance = new ImageLoaderHelper();
    }

    public static ImageLoaderHelper getInstance() {
        return Instance.instance;
    }

    private ImageLoaderHelper() {
    }

    public void GlideImageLoader(Context context, String url, ImageView imageView, int defaultPic) {
        Glide.with(context.getApplicationContext()).load(url).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).placeholder(defaultPic).into(imageView);
    }

    public void GlideImageLoader(Context context, String url, ImageView imageView) {
        Glide.with(context.getApplicationContext()).load(url).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).into(imageView);
    }
    /**
     * Glide加载圆形图片
     */
    public void GlideCircleImageLoader(final Context context, String url, final ImageView imageView, final int defaultPic) {
//        if (TextUtils.isEmpty(url))
//            url = "www.joyoung.com";
        Glide.with(context.getApplicationContext()).load(url).asBitmap().placeholder(defaultPic).centerCrop().into(new BitmapImageViewTarget(imageView) {
            @Override
            protected void setResource(Bitmap resource) {
                RoundedBitmapDrawable circularBitmapDrawable =
                        RoundedBitmapDrawableFactory.create(context.getApplicationContext().getResources(), resource);
                circularBitmapDrawable.setCircular(true);
                imageView.setImageDrawable(circularBitmapDrawable);
            }
        });
    }

}
